import requests
import json

def fanyi(keyword):
	#定义请求url地址和参数：
	url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
	data = {'i':keyword}
	data['doctype']='json'

	#创建请教，发送请求，爬取信息
	res = requests.post(url,data=data)

	#解析结果
	str_json = res.content.decode('utf-8')
	#print(str_json)
	myjson = json.loads(str_json)
	print(myjson['translateResult'][0][0]['tgt'])

if __name__ == '__main__':
	while True:
		keyword = input('请输入要翻译的文字:')
		if keyword =='q':
			break
		else:
			fanyi(keyword)
